<?php
use think\Db;
use my\Tools;
use think\mongo\Connection;
use my\Security;
use my\Redis;
/**
 * 平台支出记录
 * @param $log_id 支出业务关联id
 * @param $money 支出金额
 * @param $type 支出类别
 * @param $user_id or $store_id 涉及申请用户ID或商家ID
 */
function expenseLog($data){
	$data['addtime'] = time();
	$data['admin_id'] = session('admin_id');
	M('expense_log')->add($data);
}
//获取admin信息
function getAdminInfo($admin_id,$type=''){
    $result = Db::name('admin')->where("admin_id", $admin_id)->find();
    if($type){
        return $result['user_name'];
    }else{
        return $result;
    }
}

/**
 * 面包屑导航  用于后台管理
 * 根据当前的控制器名称 和 action 方法
 */
function navigate_admin()
{
	$navigate = include APP_PATH.'admin/conf/navigate.php';
	$location = strtolower('Admin/'.CONTROLLER_NAME);
	$arr = array(
		'后台首页'=>'javascript:void();',
		$navigate[$location]['name']=>'javascript:void();',
		$navigate[$location]['action'][ACTION_NAME]=>'javascript:void();',
	);
	return $arr;
}

/**
 * 导出excel
 * @param $strTable 表格内容
 * @param $filename 文件名
 */
function downloadExcel($strTable,$filename)
{
	header("Content-type: application/vnd.ms-excel");
	header("Content-Type: application/force-download");
	header("Content-Disposition: attachment; filename=".$filename."_".date('Y-m-d').".xls");
	header('Expires:0');
	header('Pragma:public');
	echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
}

/**
 * 格式化字节大小
 * @param  number $size      字节数
 * @param  string $delimiter 数字和单位分隔符
 * @return string            格式化后的带单位的大小
 */
function format_bytes($size, $delimiter = '') {
	$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
	for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
	return round($size, 2) . $delimiter . $units[$i];
}

/**
 * 根据id获取地区名字
 * @param $regionId //id
 * @return  string
 */
function getRegionName($regionId){
	$data = M('region')->where(array('id'=>$regionId))->field('name')->find();
	return $data['name'];
}

/*菜单信息*/
function getMenuList($act_list){
	$menuArr = getAllMenu();
    $role_right = '';
	if($act_list != 'all' && !empty($act_list)){
		$right = Db::name('system_menu')->where("id", "in", $act_list)->getField('right',true);
		foreach ($right as $val){
			$role_right .= $val.',';
		}
		$role_right = explode(',', $role_right);
		foreach($menuArr as $key1=>$val1){
			foreach ($val1['child'] as $k=>$mrr){
				foreach ($mrr['sub_menu'] as $j=>$v){
				    $actArr = explode('?',$v['act']);
					if(!in_array($v['control'].'@'.$actArr[0], $role_right)){
						unset($menuArr[$key1]['child'][$k]['sub_menu'][$j]);//过滤菜单
					}
				}
			}
		}
		foreach ($menuArr as $mk=>$mr){
			foreach ($mr['child'] as $nk=>$nrr){
				if(empty($nrr['sub_menu'])){
					unset($menuArr[$mk]['child'][$nk]);
				}
			}
		}
		foreach ($menuArr as $ks => $vs) {
			if(empty($vs['child'])){
				unset($menuArr[$ks]);
			}
		}
	}
	return $menuArr;
}
/*后台菜单栏目*/
function getAllMenu(){
	return array(
	    "finance"=>array('name'=>'财务中心',
            'child'=>array(
                'balance'=>array(
                    'name' => '余额中心', 'icon'=>'&#xe65e;', 'sub_menu' => array(
                        array('name' => '钱包管理', 'act'=>'tableMoney', 'control'=>'Driver'),
                        array('name' => '司机资金流水', 'act'=>'driverFlowList', 'control'=>'Driver'),
                        array('name' => '退款列表','act'=>'index', 'control'=>'UserRechargeLog'),
                    ),
                ),
                'withdraw'=>array(
                    'name' => '提现中心', 'icon'=>'&#xe65e;', 'sub_menu' => array(
                        array('name' => '司机提现风控审核','act'=>'index','control'=>'DriverWind'),
                        array('name' => '司机余额提现列表','act'=>'index','control'=>'DriverWithdraw'),
                    ),
                ),
                /*'intercity'=>array(
                    'name' => '城际数据', 'icon'=>'&#xe629;', 'sub_menu' => array(
                        array('name' => '数据报表(城际)', 'act'=>'tableData', 'control'=>'InterOrder'),
                        array('name' => '订单图表(城际)', 'act'=>'imgData', 'control'=>'InterOrder'),
                    ),
                ),*/
            ),
        ),

        "user_center"=>array('name'=>'用户中心',
            'child'=>array(
                'user' => array('name'=>'用户管理','icon'=>'&#xe613;','sub_menu'=>array(
                    array('name'=>'用户列表','act'=>'index','control'=>'User'),
                    array('name' => '消费流水', 'act'=>'flow', 'control'=>'UserRechargeLog'),
                    array('name' => '退款记录', 'act'=>'refund', 'control'=>'UserRechargeLog'),
                )),
            ),
        ),

		"intercity"=>array('name'=>'城际管理',
            'child'=>array(
                'InterDriver' => array('name' => '城际司机', 'icon'=>'&#xe770;', 'sub_menu' => array(
                    array('name'=> '城际司机','act'=>'index?driver_type=2','control'=>'Driver'),
                    array('name'=> '城际车辆','act'=>'index?driver_type=2','control'=>'Car'),
                )),
				'InterCar' => array('name' => '路线管理', 'icon'=>'&#xe64d;', 'sub_menu' => array(
                    array('name' => '路线途径地列表', 'act'=>'index', 'control'=>'InterRoute'),
				)),
			),
		),
        "order"=>array('name'=>'订单管理',
                       'child'=>array(
                           'Order' => array('name'=>'订单中心','icon'=>'&#xe60a;','sub_menu'=>array(
                               array('name'=>'订单列表','act'=>'index','control'=>'Order'),
                           )),
                       ),

        ),
        "other"=>array('name'=>'运营中心',
            'child'=>array(
                'promotion' => array('name' => '活动管理', 'icon'=>'&#xe663;', 'sub_menu' => array(
                    array('name' => '充值送余额', 'act'=>'recharge', 'control'=>'Promotion'),
                    array('name' => '优惠券管理','act'=>'index', 'control'=>'Coupon'),
                    array('name' => '活动管理司机','act'=>'index', 'control'=>'AdminActivity'),
                    array('name' => '活动管理乘客','act'=>'passenger', 'control'=>'AdminActivity'),
                )),
                'advert' => array('name' => '广告管理', 'icon'=>'&#xe634;', 'sub_menu' => array(
                    array('name' => 'APP闪屏','act'=>'index', 'control'=>'SplashPage'),
                    array('name' => 'APP广告','act'=>'index', 'control'=>'Ad'),
                    array('name' => '分享管理','act'=>'index', 'control'=>'Share'),
                    array('name' => '公告管理','act'=>'index', 'control'=>'Notice'),
                    array('name' => '广告文章','act'=>'index', 'control'=>'BtAd'),
                )),
                'news' => array('name' => '消息管理', 'icon'=>'&#xe645;', 'sub_menu' => array(
                    array('name' => '消息中心','act'=>'index', 'control'=>'ActivityNews'),
                    array('name' => '公告管理','act'=>'index', 'control'=>'Notice'),
                    array('name' => '获取验证码','act'=>'index', 'control'=>'SmsCode'),
                    array('name' => '群发短信','act'=>'index', 'control'=>'SmsMass'),
                )),
            ),
        ),
		"system"=>array('name'=>'管理中心',
            'child'=>array(
			    'system' => array('name'=>'设置中心','icon'=>'&#xe716;','sub_menu'=>array(
				    array('name'=>'网站设置','act'=>'index','control'=>'System'),
					// array('name'=>'区域管理','act'=>'region','control'=>'System'),
                    array('name' =>'App导航设置','act'=>'index','control'=>'RegionCar'),
                    array('name' =>'APP版本设置','act'=>'user_app','control'=>'Version'),
				)),
                'carbrand' => array('name' => '通用配置', 'icon'=>'&#xe614;', 'sub_menu' => array(
                    array('name' =>'车辆品牌','act'=>'index','control'=>'CarBrand'),
                    array('name' =>'车辆类型','act'=>'index','control'=>'CarType'),
                    array('name' => '投诉配置','act'=>'index', 'control'=>'ComplainMessage'),
                    array('name' => '设置白名单', 'act'=>'add', 'control'=>'WhiteList'),
                    array('name'=>'会员设置','act'=>'zone','control'=>'Member'),
                    array('name'=>'热门城市','act'=>'index','control'=>'HotCity'),
                    array('name'=>'网站文章','act'=>'index','control'=>'About'),
                )),
				/*'upload' => array('name'=>'监管中心','icon'=>'&#xe679;','sub_menu'=>array(
				    array('name'=>'平台备案','act'=>'ptba','control'=>'System'),
					array('name'=>'公司机构信息','act'=>'jgxx','control'=>'System'),
					array('name'=>'运价信息','act'=>'yjxx','control'=>'System'),
					array('name'=>'结算周期','act'=>'jszq','control'=>'System'),
				)),*/
                'access' => array('name' => '权限中心', 'icon'=>'&#xe653;', 'sub_menu' => array(
                    array('name' => '权限列表','act'=>'right_list','control'=>'System'),
                    array('name' => '权限组列表', 'act'=>'groupList', 'control'=>'System'),
                    array('name' => '角色列表', 'act'=>'role', 'control'=>'Admin'),
                    array('name' => '管理员列表', 'act'=>'index', 'control'=>'Admin'),
                )),
				'logs' => array('name' => '日志中心', 'icon'=>'&#xe6b2;', 'sub_menu' => array(
				    array('name' => '管理员日志', 'act'=>'index', 'control'=>'AdminLog'),
					//array('name'=>  'APP操作日志','act'=>'index','control'=>'AppLog'),
					array('name' => '用户登录日志','act'=>'index','control'=>'UserLoginLog'),
					array('name' => '城内订单下单日志', 'act'=>'index', 'control'=>'OrderLog'),
					array('name' => '城内订单结算日志', 'act'=>'index', 'control'=>'PayLog'),
					array('name' => '城内订单轨迹日志', 'act'=>'index', 'control'=>'OrderLocalLog'),
					array('name' => '城内司机登录日志', 'act'=>'index', 'control'=>'DriverLoginLog'),
//					array('name' => '城际订单下单日志', 'act'=>'index', 'control'=>'InterOrderLog'),
//					array('name' => '城际订单结算日志', 'act'=>'index', 'control'=>'InterPayLog'),
//					array('name' => '城际订单分派日志', 'act'=>'index', 'control'=>'InterAllotLog'),
//					array('name' => '城际订单轨迹日志', 'act'=>'index', 'control'=>'InterOrderLocalLog'),
//					array('name' => '城际司机登录日志', 'act'=>'index', 'control'=>'InterDriverLoginLog'),
//                    array('name' => '监管数据上传日志', 'act'=>'index', 'control'=>'DataUploadLog'),
                )),
            ),
		),
	);
}

/*获取权限组*/
function getGroup(){
	$list = Db::name('admin_auth_group')->order('sort asc,id asc')->select();
	$group = array();
	foreach ($list as $key => $value) {
		$group[$value['kname']] = $value['kval'];
	}
	return $group;
}

function respose($res){
	exit(json_encode($res));
}

function get_driver_detail_column(){
	return array(
		'driver_name'   =>'姓名',
		'driver_phone'  =>'联系方式',
		'driver_avatar' =>'头像',
		'auth_status'   =>'认证状态',
		'id_number'     =>'身份证号码',
		'work_province' =>'认证区域',
		'auth_type'     =>'认证类型',
		'last_login_time'=>'上次登陆时间',
		'register_time' =>'注册时间',
		'register_ip'   =>'注册IP',
		'license_time'  =>'驾驶证注册时间',
		'valid_time'    =>'驾驶证有效时间',
		'register_port' =>'注册端口',
		'register_city' =>'注册城市',
		'register_MAC'  =>'移动终端硬件标识',
		'register_IMSI' =>'国际移动用户识别码',
		'register_IMEI' =>'国际移动设备身份码',
	);
}

function get_car_detail_column(){
	return array(
		'driver_name'   =>'姓名',
		'driver_phone'  =>'联系方式',
		'auth_status'   =>'认证状态',
		'id_number'     =>'身份证号码',
		'work_province'=>'认证区域',
        //'register_city' =>'认证区域',
        'seats'         =>'座位数',
        'car_vin'       =>'车辆识别码',
        'vin'           =>'发动机车架号',
		'auth_type'     =>'认证类型',
		'car_plate'     =>'车牌',
		'car_brand'     =>'车辆品牌',
		'car_model'     =>'车辆型号',
		'color'         =>'颜色',
		'owner'         =>'车辆所有人',
		'register_at'   =>'车辆注册时间',
		'taxi_license_number'=>'营运证件号码',
		'license_number'=>'驾驶证号码',
		'company'       =>'车辆所属公司',
		'frame_number'  =>'车架号',
	);
}

function get_user_detail_column(){
	return array(
		'user_phone'    =>'联系方式',
		'avatar'        =>'头像',
		'last_login_time'=>'上次登陆时间',
		'register_time' =>'注册时间',
		'register_ip'   =>'注册IP',
		'register_port' =>'注册端口',
		'register_city' =>'注册城市',
		'register_MAC'  =>'移动终端硬件标识',
		'register_IMSI' =>'国际移动用户识别码',
		'register_IMEI' =>'国际移动设备身份码',
	);
}

function sendmes($phone,$content,$type=1){
    //引入文件
	include_once VENDOR_PATH."Alidayu/TopSdk.php";
	$c = new TopClient();
	$c->appkey = '23815139';  //申请的appkey
	$c->secretKey = '1936def6e0a5fa506b3ceed72febcc9c';      //申请的secreKey
	$req = new AlibabaAliqinFcSmsNumSendRequest();
	$req->setExtend("123456");
	$req->setSmsType("normal");
	$req->setSmsFreeSignName("小马出行");  //测试名
	// 生成验证码
	if($type==1){
		$code = $content;
		$req->setSmsParam("{\"code\":\"".$code."\",\"product\":\"小马出行\"}"); //验证码
		$req->setSmsTemplateCode("SMS_66680212");//模板ID
		$t="验证码";
	}elseif($type==2){
		$starttime=$content['starttime'];
		$startaddress=$content['startaddress'];
		$req->setSmsParam("{\"starttime\":\"".$starttime."\",\"startaddress\":\"".$startaddress."\"}"); //通知司机新订单
		$req->setSmsTemplateCode("SMS_66730335");//模板ID
		$t="通知司机新订单";
	}elseif($type==3){
		$starttime=$content['starttime'];
		$startaddress=$content['startaddress'];
		$count=$content['count'];
		$req->setSmsParam("{\"starttime\":\"".$starttime."\",\"startaddress\":\"".$startaddress."\",\"count\":\"".$count."\"}"); //通知客服新订单
		$req->setSmsTemplateCode("SMS_66765395");//模板ID
		$t="通知客服新订单";
	}elseif($type==4){
		//请注意有上车扫码的乘客退单，订单号为:${osn}
		$osn=$content['osn'];
		$req->setSmsParam("{\"osn\":\"".$osn."\"}"); //通知客服上车付款退单
		$req->setSmsTemplateCode("SMS_66685361");//模板ID
		$t="通知客服上车付款退单";
	}elseif($type==5){
		$osn=$content['osn'];
		$req->setSmsParam("{\"osn\":\"".$osn."\"}"); //通知客服付款后的退单
		$req->setSmsTemplateCode("SMS_66835351");//模板ID
	}elseif($type==6){
		$money=$content['money'];
		$req->setSmsParam("{\"xmcoupon\":\"".$money."\"}"); //通知客服付款后的退单
		$req->setSmsTemplateCode("SMS_69750157");//模板ID
		$t="通知乘客优惠券";
	}elseif($type==7){
		$name=$content['name'];
		$req->setSmsParam("{\"name\":\"".$name."\"}"); //通知客服付款后的退单
		$req->setSmsTemplateCode("SMS_70075337");//模板ID
		$t="通知司机招募";
	}elseif($type==8){
		$month=$content['month'];
		$day=$content['day'];
		$hour=$content['hour'];
		$minute=$content['minute'];
		$name=$content['name'];
		$price=$content['price'];
		$money=$content['money'];
		$req->
		setSmsParam("{\"month\":\"".$month."\",\"day\":\"".$day."\",\"hour\":\"".$hour."\",\"minute\":\"".$minute."\",\"name\":\"".$name."\",\"price\":\"".$price."\",\"money\":\"".$money."\"}"); //通知客服新订单
		$req->setSmsTemplateCode("SMS_73805011");//模板ID
		$t="通知司机奖励";
	}
	admin_log('系统','给'.$phone.'发短信'.','.$t);
	$req->setRecNum($phone);//发送电话号码
	//S('code'.$phone,$code,300);
}

function get_invoice_common_column(){
	return array(
		'invoice_sn'    => '发票流水号',
		'money'         => '发票金额',
		'title_type'    => '抬头类型',
		'title'         => '发票抬头',
		'taxpayerId'    => '纳税人识别号',
		'remark'        => '备注',
		'register_address'=> '注册地址',
		'register_phone'=> '注册电话',
		'bank'          => '开户行',
		'account'       => '银行账号',
		'addressee'     => '收件人',
		'addressee_phone'=> '收件人电话',
		'addressee_address'=> '收件人地址',
		'postage'       => '邮费',
		'add_time'      => '申请时间',
		'invoice_status'=> '发票状态',
		'is_free'       => '是否包邮',
	);
}

function record_type(){
	return array(1=>'车辆审核',2=>'头像审核',);
}

function log_json($data,$content,$controls){
	$a_log['IP'] = Tools::getIp();
	if(strpos($a_log['IP'],'192.168.')===false && strpos($a_log['IP'],'127.0.0.')===false){
		$a_log['controls'] = $controls;
		$a_log['content'] = $content;
		$a_log['add_time'] = time();
		$a_log['admin_name'] = session('admin_name');
		$data&&$a_log['param'] = json_encode($data);
		Db::name('admin_log')->insertGetId($a_log);
	}
	return json($data);
}
//管理级别
function admin_type(){
	return array(
		1=>'超级管理（全国）',2=>'省级管理',3=>'市级管理',4=>'区县级管理',5=>'加盟商管理'
	);
}
//会员流水类型
function typeName($type=''){
    $typeNameArr = ['1'=>'收入(钻石)','2'=>'收入(黄金)','3'=>'提现'];
    return $typeNameArr[$type];
}
//
function orderTypeName($type=''){
    $orderTypeNameArr = ['1'=>'顺风车','2'=>'城内','3'=>'城际'];
    return $orderTypeNameArr[$type];
}

function inner_order_detail_column(){
	return array(
		'order_sn'      => '订单号',
		'order_status'  => '订单状态',
		'user_phone'    => '用户手机号',
		'start_name'    => '出发地',
		'arrive_name'   => '目的地',
		'on_car_time'   => '上车时间',
		'off_car_time'  => '下车时间',
		'driver_name'   => '司机姓名',
		'driver_phone'  => '司机手机号',
		'car_plate'     => '车牌号',
		'car_brand'     => '车辆品牌',
		'car_model'     => '车辆型号',
		'color'         => '颜色',
		'driver_avatar' => '司机头像',
		'license'       => '司机驾驶证',
		'permit'        => '司机行驶证',
	);
}
//删除文件目录
function del_dir($dir) {
	$dh=opendir($dir);
	while ($file=readdir($dh)) {
		if($file!="." && $file!="..") {
			$fullpath=$dir."/".$file;
			if(!is_dir($fullpath)) {
				@unlink($fullpath);
			} else {
				del_dir($fullpath);
			}
		}
	}
	closedir($dh);
	if(rmdir($dir)) {
		return true;
	} else {
		return false;
	}
}

//审核状态
function check_status(){
    return array(1=>'待审核',2=>'已审核',3=>'异常',4=>'未通过');
}

//支付状态
function pay_status()
{
    return array(1=>'待支付',2=>'已支付',3=>'支付失败',4=>'支付异常');
}

//顺风车订单状态
function frOrderStatusInfo($order_status = ''){
    $data = [
        '0' => '等待司机',
        '5' => '司机取消',
        '10' => '系统取消',
        '15' => '用户取消',
        '16' => '司机已接单',
        '20' => '未上车',
        '30' => '已付款',
        '31' => '司机去接乘客',
        '40' => '已上车',
        '45' => '已到达',
        '50' => '已评价'
    ];
    if($order_status !== ''){
        return $data[$order_status];
    }else{
        return $data;
    }
}
//活动类型
function acitivetyType($activityType=''){
    $activityTypeArr = ['1'=>'顺风车主首单奖励','2'=>'冲单奖励','5'=>'邀请顺风车主认证','3'=>'邀请顺风车主完成首单','4'=>'邀请返现金','6'=>'邀请快车司机认证','7'=>'累计在线时长奖励','8'=>'连续在线时长奖励','9'=>'分享拼手气红包','10'=>'邀请乘客完成快车首单','11'=>'邀请司机完成城际首单','12'=>'邀请乘客完成城际首单'];
    if(!empty($activityType)){
        return $activityTypeArr[$activityType];
    }else{
        return $activityTypeArr;
    }
}

//评分设置
function evaluateSorce($key=''){
    $sorceArr = [
        '1' => '1 - 星',
        '2' => '2 - 星',
        '3' => '3 - 星',
        '4' => '4 - 星',
        '5' => '5 - 星',
    ];
    if(!empty($key)){
        return $sorceArr[$key];
    }else{
        return $sorceArr;
    }
}
//积分类型
function integralType($key=''){
    $arr = [
        '1' => '商城-订单',
        '2' => '商城订单退款',
        '3' => '兑换',
        '4' => '活动奖励(司机)',
    ];
    if(!empty($key)){
        return $arr[$key];
    }else{
        return $arr;
    }
}
//秒数转换为时分 get_second_h_m(8000)
function get_second_h_m($v){
    $h=floor($v/3600);
    if($h<10){$h='0'.$h;}
    $t=$v%3600;
    $m=floor($t/60);
    if($m<10){$m='0'.$m;}
    return $h.' 时 '.$m.' 分';
}

/*
 * 获取司机+用户的极光ID
 * $id (用户/司机ID)
 * $type 1用户2司机
*/
function aurora_id($id='',$type=''){
    if($type == 2){
        $registration_id = Db::name('driver_info')->where(['driver_id'=>$id])->value('registration_id');
    }else{
        $registration_id = Db::name('user')->where(['uid'=>$id])->value('registration_id');
    }
    return $registration_id;
}

//合作平台各级分润  订单来源
function profit_source_type() {
    return array(1 => "小马海购", 2 => "海宝商城");
}

//合作平台各级分润  订单类型
function profit_order_type() {
    return array(1 => "普通订单", 2 => "398套餐");
}

//合作平台各级分润 分润方式
function profit_fixed_type() {
    return array(0 => "比例(%)", 1 => "固定金额");
}

//用户流水类型
function user_flow_type($key=''){
    $result = [
        '1'=>'充值',
        '2'=>'城内订单消费',
        '3'=>'签到',
        '4'=>'退款',
        '5'=>'扣款',
        '6'=>'城际订单消费',
        '7'=>'顺风车消费',
        '8'=>'顺风车车主收入',
        '9'=>'顺风车车主罚款',
        '10'=>'提现',
        '11'=>'会员缴费',
        '12'=>'活动奖励',
        '13'=>'会员提现',
        '14'=>'城际拼车退款',
        '15'=>'顺风车有责取消费',
        '16'=>'海宝付款',
        '17'=>'海宝退款',
        '18'=>'海购商城付款',
        '19'=>'海购商城退款',
        '20'=>'城际拼车有责取消费',
        '21'=>'使用赠送金',
        '22'=>'退回赠送金'
    ];
    if(!empty($key)){
        return $result[$key];
    }else{
        return $result;
    }
}
//司机流水类型
function driver_flow_type($key=''){
    $result = ['1'=>'收入','2'=>'提现','3'=>'罚款','4'=>'奖励','5'=>'异常冻结','6'=>'异常冻结罚款'];
    if(!empty($key)){
        return $result[$key];
    }else{
        return $result;
    }
}
//司机流水类型
function GetDriverListMongo($data){
    $drivetType    = !empty($data['drivetType'])?$data['drivetType']:0;     //省份搜索
    $province_id    = !empty($data['province_id'])?$data['province_id']:13;     //省份搜索
    $city_id        = !empty($data['city_id'])?$data['city_id']:133;            //城市搜索
    $driver_name    = !empty($data['driver_name'])?$data['driver_name']:'';     //司机姓名
    $driver_phone   = !empty($data['driver_phone'])?$data['driver_phone']:'';   //司机手机号
    $where          = [];
    if(!empty($driver_name)){
        $driverInfo = Db::name('driver_base')->where(['driver_name'=>['like','%'.$driver_name.'%']])->field('driver_id')->select();
        $driverArrId = [];
        foreach ($driverInfo as $key=>$value){
            $driverArrId[] = $value['driver_id'];
        }
        $where['a.driver_id'] = ['in',implode(',',$driverArrId)];
    }
    if(!empty($driver_phone)){
        $where['a.driver_id'] = Db::name('driver_base')->where(['driver_phone'=>Security::encrypt($driver_phone)])->value('driver_id');
    }
    $mongoCollection    = new Connection();
    $driverLocation     = $mongoCollection->table("live_driver_location")->field('driverId,location,createTime,direction')->select();
    $driverIdArr        = [];
    $driverLocationArr  = [];
    $dqtime=strtotime(date('Y-m-d'));//当前时间戳
    foreach ($driverLocation as $key =>$value){                                                                     //第一层过滤司机
        if(!empty($value['createTime'])){
            $createTime = substr($value['createTime'], 0, -3);
            if(strstr($value['createTime'],':')){
                $createTime = strtotime($value['createTime']);
            }
            if($createTime > $dqtime){
                $driverIdArr[] = $value['driverId'];
                $driverLocationArr[$value['driverId']] = $value;
            }
        }
    }
    //查询这些司机的认证城市 - 并且是否认证通过 - 符合的司机信息
    $driverList = Db::name('car_info')->alias('a')->field('a.driver_id as driverId,b.driver_name as name,b.driver_phone')->join('driver_base b','a.driver_id = b.driver_id','left')->where(['a.driver_id'=>['in',implode(',',$driverIdArr)],'a.work_province'=>$province_id,'a.work_city'=>$city_id,'b.auth_status'=>1])->where($where)->select();
    foreach ($driverList as $key=>$value){
        $driverList[$key]['driver_phone'] = Security::decrypt($value['driver_phone']);
    }
    //符合的司机
    $redis = new Redis();
    foreach ($driverList as $key=>$value){
        $driverLocal = [];
        if(!empty($driverLocationArr[$value['driverId']])){        //不为空
            $hashKey                = 'driver_id:'.$value['driverId'];
            //判断上一次司机坐标哈希数据是否存在
            if($redis->Exists($hashKey)){
                $driverLocal        = $redis->hGetAll($hashKey);
                if($driverLocal['lng'] == $driverLocationArr[$value['driverId']]['location']['coordinates'][0] && $driverLocal['lat'] == $driverLocationArr[$value['driverId']]['location']['coordinates'][1]){
                    $driverList[$key]['localType']      = 1;
                    $driverList[$key]['time']           = get_second_h_m(time() - $driverLocal['time']);
                    $driverList[$key]['sumTime']        = time() - $driverLocal['time'];
                }else{
                    $driverList[$key]['localType']      = 0;
                    $driverList[$key]['time']           = '-';
                    $driverList[$key]['sumTime']        = 0;
                    $driverLocal = [
                        'time'          => time(),
                        'lng'           => $driverLocationArr[$value['driverId']]['location']['coordinates'][0],
                        'lat'           => $driverLocationArr[$value['driverId']]['location']['coordinates'][1]
                    ];
                    $redis->hMSet($hashKey,$driverLocal);
                }
            }else{
                $driverList[$key]['localType']          = 0;
                $driverList[$key]['time']               = '-';
                $driverList[$key]['sumTime']            = 0;
                $driverLocal = [
                    'time'          => time(),
                    'lng'           => $driverLocationArr[$value['driverId']]['location']['coordinates'][0],
                    'lat'           => $driverLocationArr[$value['driverId']]['location']['coordinates'][1]
                ];
                $redis->hMSet($hashKey,$driverLocal);
            }
            $driverList[$key]['lng']        = $driverLocationArr[$value['driverId']]['location']['coordinates'][0];
            $driverList[$key]['lat']        = $driverLocationArr[$value['driverId']]['location']['coordinates'][1];
            $driverList[$key]['old_lng']    = !empty($driverLocal['lng'])?$driverLocal['lng']:'';
            $driverList[$key]['old_lat']    = !empty($driverLocal['lat'])?$driverLocal['lat']:'';
            $driverList[$key]['center']     = $driverLocationArr[$value['driverId']]['location']['coordinates'][0].','.$driverLocationArr[$value['driverId']]['location']['coordinates'][1];
            $driverList[$key]['direction']  = $driverLocationArr[$value['driverId']]['direction'];
        }
    }
    return $driverList;
}

